﻿using System;
using System.Drawing;
using System.Linq;
using CommonBehaviors.Actions;
using Altarboy;
using Styx;
using Styx.Helpers;
using Styx.Logic.Combat;
using Styx.Logic.Inventory;
using Styx.Logic.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using TreeSharp;
using Action = TreeSharp.Action;

namespace Altarboy
{
    class WarlockComposites
    {
        #region Delegates
        public delegate bool SimpleBoolReturnDelegate(object context);
        public delegate WoWUnit UnitSelectionDelegate(object context);
        #endregion

        // Current Player   
        public static LocalPlayer Me { get { return StyxWoW.Me; } }
        public static WoWUnit Minion { get { return StyxWoW.Me.Pet; } }

        public static Composite CommonWarlockBuffs()
        {
            return new Decorator(ret => !CastManager.IsHymning(),
               new PrioritySelector(
                  // Will need setting to toggle Fel Armor and Demon Armor
                  AltarboyComposites.BuffSelf("Fel Armor", ret => (true)),
                  AltarboyComposites.CastSpell("Summon Felhunter", ret => (Minion == null || Minion.Dead), Me),
                  AltarboyComposites.BuffSelf("Soul Link", ret => (StyxWoW.Me.GotAlivePet))
              ));
        }

        public static bool ShouldLifeTap(WoWUnit unit)
        {
            if (AuraManager.HasAuraStacks("Tormented", 0, Me)) { return false; }  //Baleroc FL Crystal Debuff (150% damage)
            if (AuraManager.HasAuraStacks("Torment", 0, Me)) { return false; }  //Baleroc FL Crystal Debuff (150% damage)              
            //if (TargetManager.IsUnsafeShadowWordDeath(unit)) { return false; } 
            if (Me.ManaPercent <= 50 && Me.HealthPercent >= 80 && Me.IsMoving) { Logging.Write("Health {0:F0}% Mana: {1:F0}% Moving: True", Me.HealthPercent, Me.ManaPercent); return true; }
            if (Me.ManaPercent <= 30 && Me.HealthPercent >= 80 && !Me.IsMoving) { Logging.Write("Health {0:F0}% Mana: {1:F0}% Moving: False", Me.HealthPercent, Me.ManaPercent); return true; }
            return false;
        }


    }
}
